<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$jigouid=$this->checklogin();
if($_RQ['op']=='edit'){
	$item=pdo_get('jy_chengedu_jigou',array('id'=>$jigouid));
	$item['yajinfee']=$return['basic']['yajin'];
    $return['item']=$item;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'jigouid'=>$jigouid,
			'mid'=>$_SESSION['uid'],
			'fee'=>intval($return['basic']['yajin']),
			'createtime'=>TIMESTAMP
	);
	pdo_insert('jy_chengedu_yajin_log',$insert);
	$order_id=pdo_insertid();
	$params=array(
		'id'=>$order_id,
		'title'=>'机构入驻金',
		'fee'=>intval($return['basic']['yajin']),
		//'pay_type'=>'wechat',//可选，此项作用为指定支付方式
		'no_type'=>array('hdfk'),//可选，此项作用为指定不允许使用哪种支付方式
		'back_url'=>'jy_chengedu/manage.setyajin/payresult/',//必填，指定异步支付结果通知地址，采用系统标准URL书写格式
		'success_url'=>$success_url?:'jy_chengedu/manage.index/',
		'error_url'=>$error_url?:'jy_chengedu/manage.index/',
	);
	$payid=cfc('pay')->create_pay_order($params);
	$this->pdo_update('yajin_log',array('pay_id'=>$payid),array('id'=>$order_id));
	$res=array(
		'pay_id'=>$payid,
		'order_id'=>$order_id,
		'success_url'=>$success_url,
		'error_url'=>$error_url,
	);
	exi($res);
}
if($_RQ['op']=='payresult'){
	$payresult=$_SESSION['pay_result'];
	if($payresult['status']!=1 && $payresult['pay_type'] !='hdfk'){
		exi('支付失败。','error','jy_chengedu/manage.index/');
	}
	$order=pdo_get('jy_chengedu_yajin_log',array('id'=>$payresult['id']));
	if($order['ispay'] ==1){
		exi('该订单已经支付！','error','jy_chengedu/manage.index/');
	}
	if($order['fee']!=$payresult['fee']){
		exi('支付失败！订单金额不匹配！'.$order['fee'].'|'.$payresult['fee'],'error','jy_chengedu/manage.index/');
	}
	pdo_update('jy_chengedu_jigou',array('is_yajinfee +='=>$order['fee']),array('id'=>$jigouid));
	$update=array(
		'paytype'=>$payresult['pay_type'],
		'transid'=>$payresult['transaction_id'],
	);
	pdo_update('jy_chengedu_yajin_log',$update,array('id'=>$payresult['id']));
	exi('提交成功!');
}
?>